package user;

public class Student extends User {
    private String class_ = "暂无";
    private double score;
    private int num;
    public static int totalStu;//统计学生总人数

    public Student(String name, char sex, int age, String id, String password, String phoneNum, String class_, double score) {
        super(name, sex, age, id, password, phoneNum);
        this.class_ = class_;
        this.score = score;
        totalStu++;
        this.num = totalStu;
    }

    public void setScore(double score) {
        this.score = score;
    }

    public void setClass_(String class_) {
        this.class_ = class_;
    }

    public double getScore() {
        return score;
    }

    public String getClass_() {
        return class_;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    //重写Object方法,判断两个学生对象的属性值是否相等
    @Override
    public boolean equals(Object obj) {
        //判断如果比较的两个对象是同一个对象，则直接返回true
        if(this == obj) {
            return true;
        }
        //类型判断
        if(obj instanceof Student) {
            //向下转型，得到obj的各个属性
            Student stu = (Student)obj;
            return this.getName().equals(stu.getName()) && this.getAge() == ((Student) obj).getAge() &&
                    this.getSex() == ((Student) obj).getSex() && this.getClass_().equals(((Student) obj).class_);
        }
        return false;
    }

    @Override
    public String toString() {
        return getNum() +
                "\t\t" + getName() +
                "\t\t" + getSex() +
                "\t\t" + getAge() +
                "\t\t" + getId() +
                "\t" + getPassword() +
                "\t\t" + getPhoneNum() +
                "\t\t" + class_ +
                "\t\t" + score;
    }

}
